<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        img{
            width: 100px;
            height: 100px;
        }
    </style>
</head>
<body>
    <button>切换</button>

    <img src="" alt="无">
    <script>
        let arr = [
            'https://s21.ax1x.com/2024/07/17/pkopN0U.jpg',
            'https://s21.ax1x.com/2024/07/17/pkoptmT.jpg',
            'https://s21.ax1x.com/2024/04/13/pFjDaPx.png',
            'https://s21.ax1x.com/2024/04/13/pFjrSL4.jpg'
        ]
        let index = 0
        let image = document.querySelector('img')
        let but = document.querySelector('button')

        // 点击事件
        but.onclick = function(){
            image.setAttribute('src',arr[index])
            // index>=3?index=0:index++
            if(index>=arr.length-1){
                index=0
            }else{
                index++
            }
            // index>arr.length-1?index=0:index++
            
            
        }


    </script>
</body>
</html>